


/*删除*/
function OperateDel(url) {
    layer.confirm('您确定要进行删除操作?', {btn: ['确定', '取消'], title: "提示"}, function () {
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            success: function (data) {
                console.log(data);
                layer.msg(data.msg, {
                    icon: 6,
                    time: 500,
                }, function () {
                    window.location.reload();
                })
            }
        })
    });
}

function OperateStop(url) {
    layer.confirm('您确定要进行操作?', {btn: ['确定', '取消'], title: "提示"}, function () {
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            success: function (data) {
                console.log(data);
                layer.msg(data.msg, {
                    icon: 6,
                    time: 500,
                }, function () {
                    window.location.reload();
                })
            }
        })
    });
}




/*
* 地区联动
* */
var _region = function () {
    layui.use(['form'], function(){
        var form = layui.form;

        form.on('select(province)', function (data) {

            // 获取下拉框定义的 id
            var type = data.elem.getAttribute("id");
            // 获取下拉框的值
            var type_id = data.value;

            if(type == "province"){
                _region_c(type, type_id, 'city');
            }else if(type == "city"){
                _region_c(type, type_id, 'area');
            }else if(type == "area"){
                _region_c(type, type_id, 'street');
            }
        })
    });
}

var _region_c = function (type, type_id, lk) {

    if (type == "province") {
        $("#city,#area,#street").html("<option value=''>请选择</option>");
    }
    if (type == "city") {
        $("#area,#street").html("<option value=''>请选择</option>");
    }
    if (type == "area") {
        $("#street").html("<option value=''>请选择</option>");
    }

    if (type_id == "") {
        return false;
    }

    layui.use(['form'], function(){
        var form = layui.form;

        $.ajax({
            url: "/main/region",
            type: 'post',
            data: {type_id: type_id},
            dataType: 'json',
            success: function (data) {

                console.log(data);
                $.each(data.data, function (k, v) {
                    console.log(lk);
                    $("#" + lk).append("<option value=" + v.id + ">" + v.name + "</option>");
                    form.render();
                });
            }
        })
    });

};